#define opentree(x,placeholder)

<input type="text" id="_#(x.index??)_INPUT" name="#(table??x.table).#(x.tail??)" #(x.required??) #(x.disabled??) #(x.readonly??) placeholder="#(placeholder??)"  class="form-control" autocomplete="off"/>
<input type="hidden" id="_#(x.index??)" data-type="opentree" name="#(table??x.table).#(x.index??)" value="#(x.value??)" />


<script type="text/javascript">
	$(function(){
		#(x.index??)_opentree = [];
		if("#(x.readonly??)" != "readonly" && "#(x.disabled??)" != "disabled"){
			$("#_#(x.index??)_INPUT").bind("click",function(){
				#setLocal(ename = encodeUrl(x.name))
				var val = $("#_#(x.index??)").val();
				var urlParaSeparator = "-";
				val = (val == "") ? 0 : val;
				var source = "#(x.source??'')".encode();
				var opentreeH = $(window).height()+"px";
				layer.open({
	        	    type: 2,
	        	    title:"树形选择",
	        	    area: ["250px", opentreeH],
	        	    fix: false, ###不固定
	        	    maxmin: true,
	        	    content: "/ztree/open/"
						+"#(x.type??0)"+urlParaSeparator
						+"_#(x.index??0)"+urlParaSeparator
						+"#(ename??0)"+urlParaSeparator
						+source+urlParaSeparator
						+"#(x.check??0)"+urlParaSeparator
						+"#(x.where??)"+urlParaSeparator
						+"#(x.intercept??0)"+urlParaSeparator
						+"#(x.ext??0)"+urlParaSeparator + val
						+urlParaSeparator + "#(x.search??false)"
						+urlParaSeparator + "#(x.async??false)"
						+urlParaSeparator + "#(x.initParam??'')"
						+urlParaSeparator + "#(x.Y??'')"
						+urlParaSeparator + "#(x.N??'')"
	        	});
			});
		}
		if("#(x.init)"=="true"){
			if($("#_#(x.index??)").val() != ""){
				_#(x.index??)_initOpenTree($("#_#(x.index??)").val());
			}
		}
	});
	
	function #(x.index??)_readonly(){
		$("#_#(x.index??)_INPUT").attr("readonly","readonly");
		$("#_#(x.index??)_INPUT").unbind("click");
	}
	
	function _#(x.index??)_initOpenTree(val){
		var source = "#(x.source??'')".encode();
		var url="/ztree/getTreeListName/"+val;
		#if(x.async??false)
			url="/ztree/getTreeListNameAsync/"+val;
		#end
		$.post(url,{source:source, type:"#(x.type??)", where:"#(x.where??)", intercept:"#(x.intercept??)", val:val},function(data){
			if(data.state == 'ok'){
				var name = data.data.name;
				var nodes = data.data.nodes;
				#(x.index??)_opentree = nodes;
				$("#_#(x.index??)_INPUT").val(name);
			}
		}, "json");
	}
</script>
#end